//
//  NKBarChartWeeklyView.swift
//  Nokia
//
//  Created by 易先生 on 2022/4/1.
//

import UIKit
import MYModule

open class HorizontalTitleView: StackView {

   
        var font: UIFont = Fonts.systemFont(ofSize: 10) {
            
            didSet {
                
                for label in self.labels {
                    label.font = font
                }
                
            }
            
        }
        var textColor: UIColor = UIColor.assist_D0D0D0 {
            
            didSet {
                
                for label in self.labels {
                    label.textColor = textColor
                }
                
            }
        }
        
        var labels: [UILabel] {
            
            return self.subviews.compactMap {
                
                return $0 as? UILabel
            }
        }
    
    
        var titles: [String]? {
            
            willSet {
                
                guard let newValue = newValue else {
                    
                    return
                    
                }
                
                if titles == newValue {
                    return
                }
                
                // 删除旧的
                for view in self.subviews {
                    view.removeFromSuperview()
                }
                
                // 添加新的
                _ = newValue.map {[weak self] (text) ->UILabel in
                    
                    let label = UILabel()
                    label.text = text
                    label.font = self?.font
                    label.textColor = self?.textColor
                    
                    self?.addArrangedSubview(label)
                    
                    return label
                }
            }
            
            
        }
    
    open override func makeUI() {
        
        distribution = .equalSpacing
    }
}
